Ext.define('PJ.view.studentfeedbackministries.ViewFeedbackList', {
    extend: 'AM.default.DefaultList',
	alias: 'widget.st_viewSignupStatusList',
	
    initComponent: function(){
    	var me = this;
        this.columns = [{
            header: '审核状态',
            dataIndex: 't.auditingState',
            width: 125,
            //sortable: false,
            renderer: function(v, meta, record){
            	meta.style="padding-bottom: 0px;padding-top: 0px;line-height: 19px;padding-left: 0px;";
                var text = "",tipText="";
                if (v == 3) {
                	tipText="报名待审核";
                	text= '<div style="border-left:5px solid white;height:19px;padding-left:2px;">报名待审核</div>';
                }
                else if (v == 1) {
                	text= '<div style="border-left:5px solid green;height:19px;padding-left:2px;">报名通过</div>';
                	tipText="报名通过";
                }else if (v == 2) {
                	tipText="点击查看驳回原因";
                	text= '<div style="border-left:5px solid red;height:19px;cursor: pointer;padding-left:2px;"><span style="cursor: pointer;color:blue;">报名未通过</span></div>';
                }else if(v == 4){
                	tipText="撤销待审核";
                	text= '<div style="border-left:5px solid white;height:19px;padding-left:2px;">撤销待审核</div>';
                }else if(v == 5){
                	tipText="报名通过(撤销未通过)";
                	text= '<div style="border-left:5px solid green;height:19px;padding-left:2px;">报名通过(<span style="cursor: pointer;color:blue;">撤销未通过</span>)</div>';
                }
                meta.tdAttr = 'data-qtip="' + tipText + '" auditStatus=' + record.get("t.auditingState") + ' classUserId=' + record.get("classUserId") + ' userId=' + record.get("userId");
                return text;
            },
    		listeners: {
    			click: function(g, clm){
//    				var userId = clm.getAttribute("userId");
    				var auditStatus = clm.getAttribute("auditStatus");
    				var classUserId = clm.getAttribute("classUserId");
    				if(auditStatus == 5){
    					var win = Ext.create('PJ.view.registrationmanagement.CheckEdit', {
        					title: "查看驳回原因",
        					flag:4,
        					grid: me,
        					isDisable:false,
        					isReadOnly:true
        				}).show();
        				var actionName = "load";
        				if(gj_onlineLearning_constant.loadType == "jsonp"){
        					actionName = "loadJsonp";
        				}
        				win.down("form").getForm().doAction(actionName,{
        					url:me.store.findRejectReasonUrl,
        					params:{
        						classUserId: classUserId
        					},
        					success:function(f,action){
        					}
        				});
    				}else if(auditStatus == 2){
    					var win = Ext.create('PJ.view.trainingmanagement.CheckEdit', {
        					title: "查看驳回原因",
        					flag:4,
        					grid: me,
        					isDisable:false,
        					isReadOnly:true
        				}).show();
        				var actionName = "load";
        				if(gj_onlineLearning_constant.loadType == "jsonp"){
        					actionName = "loadJsonp";
        				}
        				win.down("form").getForm().doAction(actionName,{
        					url:me.store.findCommentUrl,
        					params:{
        						classUserId: classUserId
        					},
        					success:function(f,action){
        					}
        				});
    				}else{
    					return;
    				}
    			}
    		}
        },{
        	header: '学员帐号',
        	dataIndex: 't.user.loginID',
        	width: 110
        },{
        	header: '姓名',
        	dataIndex: 't.userName',
        	width: 80
        }, {
            header: '性别',
            dataIndex: 't.sexCode',
            width: 45
        },{
            header: '年龄',
            dataIndex: 't.birthday',
            width: 45,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }, {
            header: '评价状态',
            dataIndex: 't.appraiseStatus',
            width: 80,
            renderer: function(value, meta, record){
                if(value == 2){
                	return "已评价";
                }else if(value == 1){
                	return "未评价";
                }
            }
        }, {
            header: '评价内容',
            dataIndex: 't.appraise',
            flex:1,
            minWidth: 120,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '" classUserId=' + record.get("classUserId");
                return '<span style="cursor: pointer;color:blue;">' + value + '</span>';
            },
    		listeners: {
    			click: function(g, clm){
    				var classUserId = clm.getAttribute("classUserId");
    				var win = Ext.create('PJ.view.studentfeedbackministries.FeedbackEdit',{
			    		title: "学员评价",
			    		flag:1,
			    		grid: me,
			    		isReadOnly: true
			    	}).show();
					var actionName = "load";
					if(gj_onlineLearning_constant.loadType == "jsonp"){
						actionName = "loadJsonp";
					}
					win.down("form").getForm().doAction(actionName,{
						url:me.store.readReviewsUrl,
						params:{
							classUserId: classUserId
						},
						success:function(f,action){
							var data = action.response.responseText;
    	        			var json = gj_onlineLearning_constant.loadType=="ajax" ? Ext.decode(data, true) : action.response;
    	        			var form = win.down('form');	 
    	        			var baseForm = form.getForm();
    	        			baseForm.findField("appraise").setValue(json.data.appraise);
						}
					});
    			}
    		}
        }];
        this.store = Ext.create('PJ.'+prototype+'.studentfeedbackministries.ViewFeedbackList', {
            isLoad: false
        });
        this.loadType = gj_onlineLearning_constant.loadType;
        this.callParent(arguments);
    },
    /**
     * 评价
     */
    onEvaluateClick: function(){
    	var me=this;
    	var store=me.getStore();
    	var classUserIds = new Array();
    	var records=me.getSelectionModel().getSelection();
    	for(var i=0;i<records.length;i++){
    		if(records[i].get("t.appraiseStatus") == 2){
    			Orchid.alert("提示","不允许对已评价的信息进行再次评价！");
    			return;
    		}
    	}
    	for(var i=0;i<records.length;i++){
    		classUserIds.push(records[i].get('classUserId'));
    	}
    	Ext.create('PJ.view.studentfeedbackministries.FeedbackEdit',{
    		title: "学员评价",
    		flag:1,
    		grid: me,
    		commentUrl: store.commentUrl,
    		classUserIds:classUserIds,
    		searchClassID: me.up('window').classId,
    		isReadOnly: false
    	});
    },
    /**
     * 解锁
     */
    onUnlockClick: function(){
    	var me=this;
    	var store=me.getStore();
    	var records=me.getSelectionModel().getSelection();
    	for(var i=0;i<records.length;i++){
    		if(records[i].get("t.appraiseStatus") == 1){
    			Orchid.alert("提示","不允许对未评价的信息进行解锁操作！");
    			return;
    		}
    	}
    	Ext.Msg.confirm({
    		title:'提示',
    		msg:'您确定要解锁这些数据吗?',
    		icon:Ext.Msg.WARNING,
    		buttons:Ext.Msg.OKCANCEL,
    		fn:function(id){
    			if(id=='ok'){
    				var classUserIds= new Array();
    				Ext.Array.each(records,function(name,index){
    					classUserIds.push(name.get('classUserId'));
    				});
    				if(gj_onlineLearning_constant.loadType == "jsonp"){
    					var store1 = Ext.create('AM.default.jsonp.DefaultAjaxStore',{
    						loadType: gj_onlineLearning_constant.loadType,
    						url: store.unlockUrl,
    						extraParams: {
    							searchClassUserIds: classUserIds
    						}
    					});
    					store1.load(function(rec, operation, success){
    						if(success){
    							Ext.Msg.alert('消息', '解锁成功！', function(){
    								var store = me.getStore();
    								store.load();
    							});
    						}else{
    							Ext.Msg.alert('消息', operation.error);
    						}
    					});
    				}else{
    					Ext.Ajax.request({
    						url:store.unlockUrl,
    						params: {
    							searchClassUserIds: classUserIds
    						},
    						success:function(response){
    							var data=response.responseText;
    							var json=Ext.decode(data,true);
    							if(json.success){
    								Orchid.alert('提示','解锁成功!',function(){
    									store.load();
    								});
    							}else{
    								Orchid.alert('提示',json.msg);
    							}
    						}
    					});
    				}
    			}
    		}
    	});
    },
    listeners: {
    	selectionchange: function(selModel, selected){
    		this.down('#' + this.oldId + 'Evaluate').setDisabled(selected.length === 0);
    	},
    	viewready: function(){
    		this.addDocked([{
                dock: 'top',
                xtype: "searchform",
    			columnCount: 2,
    			collapsedFieldSet: false,
                fieldDefaults: {
                    xtype: "textfield",
                    labelAlign: 'right',
                    labelWidth: 80
                },
                items: [{
                    fieldLabel: '学员帐号',
                    name: "searchLoginID",
                    emptyText: "请输入学员帐号",
                    maxLength: 50
                }, {
                    fieldLabel: "姓名",
                    name: "searchUserName",
                    emptyText: "请输入姓名",
                    maxLength: 100
                },{
					xtype: "combo",
					fieldLabel: '评价状态',
					name: "appraiseStatus",
					store: Ext.create("Ext.data.ArrayStore", {
						fields: ['value', 'text'],
						data: [[1, '未评价'],[2,'已评价']]
					}),
					valueField: 'value',
					displayField: 'text',
					editable: false,
					emptyText: "请选择"
				}],
    			onResetClick: function(button){
                    var form = button.up('form');
                    var gridPanel = form.grid;
                    var newParams = {
            				searchClassID: gridPanel.up('window').classId,
            				auditingState: 1
                    };
                    gridPanel.getStore().proxy.extraParams = {};
                    var params = gridPanel.getStore().proxy.extraParams;
                    Ext.apply(params, newParams);
                    form.getForm().reset();
                },
                grid: this
            },{
                xtype: 'toolbar',
                dock: 'top',
                displayInfo: true,
                items: [{
                    text: '评价',
                    iconCls: 'studentFeedbackIco',
                    itemId: this.oldId + "Evaluate",
                    disabled: true,
                    scope: this,
                    handler: this.onEvaluateClick
                }/*, "-", {
                    xtype: 'label',
                    itemId: 'signupQuotaOfPeople',
                    html: ''
                }*/]
            }]);
    		// 触发权限过滤事件
    		this.fireEvent("permission", this);
    		var params = this.store.proxy.extraParams;
    		var newParams = {
    				searchClassID: this.up('window').classId,
    				auditingState: 1
    		};
    		Ext.apply(params, newParams);
    		this.store.isLoad = true;
    		this.store.load();
    		//this.quotaOfPeople();//单位授人数统计
    	}
    }
});
